
import javax.swing.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;



public class Test extends Frame {
         public Test(String title) {
         super(title);
      addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e){
        System.out.println("windowClosing方法被调用");
        dispose();
      }

     public void windowClosed(WindowEvent e) {
         System.out.println("windowClosed方法被调用");
         }
        });
         setSize(200, 200);
         setLocationRelativeTo(null);
         setVisible(true);
        }

        public static void main(String[] args) {
         new Test("Test");
         }
        }